
/*
//sample
window.onload=function(){
	var mask=new MaskPopup(document.body,'<input type="text" />',0.2,new Rect(new Point(0,0),new Size(200,200)));
	mask.onclose=function(dDom){
		alert(dDom.value);
	}
};
*/

//dPopupDOM can not be a DOM array.
function MaskPopup(dContainer,dPopupDOM,opacity,pos)
{
	this.dContainer=dContainer||document.body;
	this.dPopupDOM=dPopupDOM;
	this.opacity=opacity||0.7;
	this.pos=pos||{lPer:0.5,tPer:0.5};

	this.init();
}

MaskPopup.prototype={
	init:function(){
		this.dMask=document.createElement("div");
		this.dMask.innerHTML='<div class="bgmask"></div>';
		this.dMask.firstChild.style.opacity=this.opacity;
				
		this.dPopup=document.createElement("div");
		this.dPopup.innerHTML='<div class="popup"></div>';
		this.dPopup.firstChild.appendChild(this.dPopupDOM);
	},
	
	show:function(){
	
		this.dContainer.appendChild(this.dMask);
		this.dContainer.appendChild(this.dPopup);
		
		var lDiff=document.body.clientWidth-this.dPopup.firstChild.offsetWidth;
		var tDiff=document.body.clientHeight-this.dPopup.firstChild.offsetHeight;

		this.dPopup.firstChild.style.left=lDiff*this.pos.lPer;
		this.dPopup.firstChild.style.top=tDiff*this.pos.tPer;
	},
	
	close:function(){
//		var cloneNode=this.dPopup.cloneNode(true);
		this.dMask.parentNode.removeChild(this.dMask);
		this.dPopup.parentNode.removeChild(this.dPopup);
/*		var removedNode=this.dPopup.parentNode.removeChild(this.dPopup);
		if(this.onclose)
		{
			this.onclose(removedNode.firstChild);
		}
*/
	}	
}